<template>

  <el-container class="home-container">
    <el-header>
      <span></span>
        <el-button type="info" @click="logOut()">sign out</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <!--导航栏-->
        <el-menu :router="true">
          <!--一级菜单-->
          <el-submenu :index="item.path" v-for="item in menuList"  :key="item.id">
            <template slot="title">
              <i :class="iconObject[item.id]"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="it.path" v-for="it in item.subMenuList"  :key="it.id">
                <template slot="title">
                  <i :class="iconObject[it.id]"></i>
                  <span>{{ it.title }}</span>
                </template>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
export default {
  name: "Home",
  data(){
    return{
        menuList:[],  // 菜单数组
      // icon图标
      iconObject:{
        '100':'el-icon-s-custom',
        '200':'el-icon-bicycle',
        '101':'el-icon-user-solid',
        '102':'el-icon-unlock',
        '103':'el-icon-bicycle',
        '104':'el-icon-potato-strips',
        '201':'el-icon-bicycle',
        '202':'el-icon-bicycle',
        '203':'el-icon-bicycle',
      },
    };
  },
  created(){
    this.getMenuList();
  },
  methods:{
    logOut(){
      window.sessionStorage.clear(); //清除session
      this.$router.push("/login"); // 回到首页
    },
    async getMenuList(){
      const {data:res} = await this.$http.get("/menus");
      if (res.flag != 200){
        return this.$message.error("获取列表失败");
      }
      this.menuList = res.menus;
      console.log(this.menuList)
    }
  }
}
</script>

<style scoped>
.home-container{
  height: 100%;
}

.el_container{
  height: 100%;
}
.el-header{
  background-color: #d5c7e2;
  display: flex;
  justify-content: space-between;
  padding-left: 0px;
  align-items: center;
}
.el-aside{
  background-color: #ffffff;
}
.el-main{
  background-color: #ffffff;
}
</style>